﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;

namespace FluentUnity.Conventions
{
    public class LifetimeSelectionConvention
    {
        internal LifetimeManager Select(Type @interface, Type implementation)
        {
            Ensure.IsNotNull(() => @interface);
            Ensure.IsNotNull(() => implementation);

            var lifetimeAttribute = @interface.GetType().GetAttribute<LifetimeAttribute>();
            if (lifetimeAttribute != null)
                return (LifetimeManager)Activator.CreateInstance(lifetimeAttribute.Type);

            return null;
        }
    }
}